package edu.wpi.cs509.ui;

import javax.swing.JFrame;
import javax.swing.JOptionPane;

import edu.wpi.cs509.common.exceptions.IllegalMove;
import edu.wpi.cs509.common.exceptions.InvalidLocation;
import edu.wpi.cs509.common.exceptions.PieceNotFound;
import edu.wpi.cs509.representation.StrategoPiece;
import edu.wpi.cs509.ui.intfc.RulesInterface;

/**
 * Consolidates dialog windows into one file for sharing
 */
public class Dialog {
	
	static public int displayQuitConfirmDialog() {
		JFrame dialog = new JFrame();
		
		//Custom button text
		Object[] options = {"Quit",
		                    "Cancel"};
		int n = JOptionPane.showOptionDialog(dialog,
		    "Are you sure you want to Quit?",
		    "Confirm Quit",
		    JOptionPane.YES_NO_CANCEL_OPTION,
		    JOptionPane.QUESTION_MESSAGE,
		    null,
		    options,
		    options[1]);
		return n;
	}
	
	/**
	 * Notifies the user piece placement failed
	 */
	static public void displayPiecePlacementFailedDialog() {
		JFrame dialog = new JFrame();
		JOptionPane.showMessageDialog(dialog,
		    "Unable to place piece on the board", "Placement Failure",
		    JOptionPane.ERROR_MESSAGE);
	}

	static public void displayNoGamesOnServer() {
		JFrame dialog = new JFrame();
		JOptionPane.showMessageDialog(dialog, "No Games on Server", 
			null, JOptionPane.WARNING_MESSAGE);
	}

	/**
	 * Displays a dialog box to indicate the plot was selected (by mouse click),
	 * but there are not pieces of this type in the graveyard (count is zero).
	 * 
	 * @param piece_being_moved
	 */
	static public void displayNoPiecesDialog( StrategoPiece piece ) {
		JFrame dialog = new JFrame();
		JOptionPane.showMessageDialog(dialog,
		    "No pieces available", piece.toString(),
		    JOptionPane.WARNING_MESSAGE);
	}


	/**
	 * Notifies the user that the connection to the server has been
	 * lost.
	 */
	static public void displayConnectionLostDialog() {
		JFrame dialog = new JFrame();
		JOptionPane.showMessageDialog(dialog,
		    "Server Connection Lost", "Connection Failure",
		    JOptionPane.WARNING_MESSAGE);
	}

	/**
	 * Notifies the user that their login attempt failed.
	 */
	static public void displayLoginFailedDialog() {
		JFrame dialog = new JFrame();
		JOptionPane.showMessageDialog(dialog,
		    "Invalid Credentials", "Login Failure",
		    JOptionPane.WARNING_MESSAGE);
	}

	/**
	 * Notifies the user that there is already an active game 
	 */
	static public void displayOneGameDialog() {
		JFrame dialog = new JFrame();
		JOptionPane.showMessageDialog(dialog,
		    "Only one game can be played at a time", "Failed",
		    JOptionPane.WARNING_MESSAGE);
	}

	/**
	 * Notifies the user that the connection to the server was lost 
	 */
	static public void displayServerUnreachableDialog() {
		JFrame dialog = new JFrame();
		JOptionPane.showMessageDialog(dialog,
		    "The connection to the server has been lost", "Network Failure",
		    JOptionPane.WARNING_MESSAGE);
	}

	/**
	 * Displays an IllegalMove-caused error message in a dialog.
	 * 
	 * @param e - An IllegalMove exception from the client.
	 */
	static public void displayIllegalMoveDialog(IllegalMove e) {
		JFrame dialog = new JFrame();
		JOptionPane.showMessageDialog(dialog, e.getMessage(),
				"You fool!",JOptionPane.ERROR_MESSAGE);
	}
	
	/**
	 * Displays an InvalidLocation-caused error message in a dialog.
	 * 
	 * @param e - An InvalidLocation exception from the client.
	 */
	static public void displayInvalidLocationDialog(InvalidLocation e) {
		JFrame dialog = new JFrame();
		JOptionPane.showMessageDialog(dialog, e.getMessage(),
				"You fool!",JOptionPane.ERROR_MESSAGE);
	}
	
	/**
	 * Displays an PieceNotFound-caused error message in a dialog.
	 * 
	 * @param e - A PieceNotFound exception from the client.
	 */
	static public void displayPieceNotFoundDialog(PieceNotFound e) {
		JFrame dialog = new JFrame();
		JOptionPane.showMessageDialog(dialog, e.getMessage(),
				"You fool!",JOptionPane.ERROR_MESSAGE);
	}
	
	/**
	 * Displays only one location selected for move dialog
	 */
	static public void displayOneLocationSelectedDialog() {
		JFrame dialog = new JFrame();
		JOptionPane.showMessageDialog(dialog, "Move to or from location not selected",
				"You fool!",JOptionPane.ERROR_MESSAGE);
	}

}
